/*  This file is part of the comicconquer project
    Copyright (C) 2010 Reach <reach334@gmail.com>

    ComicConquer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This software is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public 
    License along with this software.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "CoGroupBox.h"

CoGroupBox::CoGroupBox(const QString& title, QWidget* parent)
: QGroupBox(title, parent),
m_layout(this)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    setLayout(&m_layout);
    addNewLine();
    m_curFocusWidget = 0;

    Out_Log(__FUNCTION__, COCLASSNAME);
}

void CoGroupBox::addNewLine()
{
    In_Log(__FUNCTION__, COCLASSNAME);

    m_curLayout = new QHBoxLayout(this);
    m_layout.addLayout(m_curLayout);

    Out_Log(__FUNCTION__, COCLASSNAME);
}

void CoGroupBox::addStretch(int stretch)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    m_curLayout->addStretch(stretch);

    Out_Log(__FUNCTION__, COCLASSNAME);
}

CoGroupBox* CoGroupBox::addGroupBox(const QString& name, const QString title)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    CoGroupBox* groupBox = new CoGroupBox(title, this); 
    m_curLayout->addWidget(groupBox);
    m_widgetMap[name] = static_cast<QWidget*>(groupBox);
    m_widgetVec.append(static_cast<QWidget*>(groupBox));

    Out_Log(__FUNCTION__, COCLASSNAME);
    return groupBox;
}

CoRadioButtonGroup* CoGroupBox::addRadioButtonGroup(const QString& name, const QStringList& texts)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    CoRadioButtonGroup* radioButtonGroup = new CoRadioButtonGroup(texts, this); 
    m_curLayout->addWidget(radioButtonGroup);
    m_widgetMap[name] = static_cast<QWidget*>(radioButtonGroup);
    m_widgetVec.append(static_cast<QWidget*>(radioButtonGroup));

    Out_Log(__FUNCTION__, COCLASSNAME);
    return radioButtonGroup;
}

CoCheckButton* CoGroupBox::addCheckButton(const QString& name, const QString& text)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    CoCheckButton* checkBox = new CoCheckButton(text, this);
    checkBox->selectOnClicked(false);
    m_curLayout->addWidget(checkBox);
    m_widgetMap[name] = checkBox;
    m_widgetVec.append(static_cast<QWidget*>(checkBox));

    Out_Log(__FUNCTION__, COCLASSNAME);
    return checkBox;
}

CoNumberEditor* CoGroupBox::addNumberEditor(const QString& name, const QString& text, const QString& unit,
                                            float max, float rate)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    CoNumberEditor* numberEditor = new CoNumberEditor(text, unit, max, rate);
    m_curLayout->addWidget(numberEditor);
    m_widgetMap[name] = numberEditor;
    m_widgetVec.append(static_cast<QWidget*>(numberEditor));

    Out_Log(__FUNCTION__, COCLASSNAME);
    return numberEditor;
}

ui::OnyxPushButton* CoGroupBox::addPushButton(const QString& name, const QString& text)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    ui::OnyxPushButton* pushButton = new ui::OnyxPushButton(text, this);
    m_curLayout->addWidget(pushButton);
    m_widgetMap[name] = pushButton;
    m_widgetVec.append(static_cast<QWidget*>(pushButton));

    Out_Log(__FUNCTION__, COCLASSNAME);
    return pushButton;
}

CoGroupBox* CoGroupBox::getGroupBox(const QString& name)
{
    return static_cast<CoGroupBox*>(m_widgetMap[name]);
}

CoRadioButtonGroup* CoGroupBox::getRadioButtonGroup(const QString& name){
    return static_cast<CoRadioButtonGroup*>(m_widgetMap[name]);
}

CoCheckButton* CoGroupBox::getCheckButton(const QString& name){
    return static_cast<CoCheckButton*>(m_widgetMap[name]);
}

CoNumberEditor* CoGroupBox::getNumberEditor(const QString& name){
    return static_cast<CoNumberEditor*>(m_widgetMap[name]);
}

